﻿namespace CodeDDD.Infrastructure.Crosscutting.Seedwork.Validator
{
    /// <summary>
    /// Entity Validator Factory
    /// </summary>
    public static class EntityValidatorFactory
    {
        #region Members

        static IEntityValidator _currentValidator = null;
        static IEntityValidatorFactory _currentFactory = null;

        #endregion

        #region Public Methods

        /// <summary>
        /// Set the log factory to use
        /// </summary>
        /// <param name="factory">Log factory to use</param>
        public static void SetCurrent(IEntityValidatorFactory factory)
        {
            _currentFactory = factory;
            _currentValidator = null;
        }

        /// <summary>
        /// Creates a new <paramref name="CodeDDD.Infrastructure.Crosscutting.Seedwork.Validator.IEntityValidator"/>
        /// </summary>
        /// <returns>Created IEntityValidator</returns>
        public static IEntityValidator GetValidator()
        {
            if (_currentValidator == null)
                _currentValidator = _currentFactory.Create();

            return _currentValidator;
        }

        #endregion
    }
}
